<template>
  <div>
    <el-table :data="lst1">
      <el-table-column prop="code" label="选择">
        <el-checkbox-group v-model="checkList" slot-scope="scope">
          <el-checkbox :label="scope.row.code"></el-checkbox>
        </el-checkbox-group>
      </el-table-column>
      <el-table-column prop="title" label="标题"> </el-table-column>
      <el-table-column prop="price" label="价格"> </el-table-column>
      <el-table-column prop="num" label="数量">
        <template slot-scope="scope">
          <el-input-number
            @change="changeNum()"
            v-model="scope.row.num"
            :min="1"
            :max="10"
            label="描述文字"
          ></el-input-number>
        </template>
      </el-table-column>
      <el-table-column prop="totalmoney" label="总价"> </el-table-column>
    </el-table>
    <el-button @click="gm">购买</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      lst1: "",
      userid: localStorage.getItem("userid"),
      checkList: [],
      token: "",
    };
  },
  mounted() {
    this.getgwc();
    this.gettoken();
  },
  methods: {
    changeNum() {
      this.lst1.map((v) => {
        v.totalmoney = v.price * v.num;
      });
    },
    getgwc() {
      this.axios.get("/getcartdata?userid=" + this.userid).then((res) => {
        this.lst1 = res.data.list;
        this.lst1.map((v) => {
          v.totalmoney = v.price * v.num;
        });
      });
    },
    gm() {
      var data = {
        checkList: this.checkList,
        userid: this.userid,
        token: this.token,
      };
      this.axios.post("/pay", data).then((res) => {
        alert(res.data.msg);
      });
    },
    gettoken() {
      this.axios.get("/gettoken1").then((res) => {
        this.token = res.data.token;
      });
    },
  },
};
</script>

<style>
</style>